﻿using System;
using System.Collections.Generic;
using System.Text;

namespace LinkUp
{
    /// <summary>
    /// 游戏玩家类
    /// </summary>
    public class User : IComparable
    {
        /// <summary>
        /// 初始化玩家信息
        /// </summary>
        /// <param name="gID"></param>
        /// <param name="gScore"></param>
        public User(string gID, int gScore)
        {
            rank = 0;
            id = gID;
            score = gScore;
            isUpload = false;
        }
        #region field and property
        private int rank;
        /// <summary>
        /// 玩家排行
        /// </summary>
        public int Rank
        {
            get { return rank; }
            set { rank = value; }
        }
        private string id;
        /// <summary>
        /// 玩家ID
        /// </summary>
        public string ID
        {
            get { return id; }
            set { id = value; }
        }
        private int score;
        /// <summary>
        /// 游戏得分
        /// </summary>
        public int Score
        {
            get { return score; }
            set { score = value; }
        }
        private bool isUpload;
        /// <summary>
        /// 是否已上传
        /// </summary>
        public bool IsUpload
        {
            get { return isUpload; }
            set { isUpload = value; }
        }
        #endregion

        #region IComparable 成员
        /// <summary>
        /// 比较两个玩家得分，以便于排序
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        int IComparable.CompareTo(object obj)
        {
            try
            {
                if (score < (obj as User).Score)
                    return 1;
                else if (score == (obj as User).Score)
                    return 0;
                else
                    return -1;
            }
            catch
            {
                throw new Exception("玩家得分排行出错！");
            }
        }
        #endregion
    }
}
